package com.bianmaba.examples.controller.authorization.user;

import com.bianmaba.examples.bean.authorization.User;
import com.bianmaba.examples.service.authorization.user.IUserService;
import com.bianmaba.spring.data.jpa.domain.PageableRequest;
import com.bianmaba.spring.mvc.controller.CrudController;
import com.bianmaba.spring.mvc.method.support.annotations.EntityParam;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import com.bianmaba.spring.mvc.method.support.annotations.MapParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;

@RestController
@RequestMapping(value = {"management/authorization/user"})
public class MGTUserController extends CrudController<User, String> {
    @Autowired
    private IUserService service;

    @Override
    protected IUserService getService() {
        return service;
    }


    @JSON()
    @RequestMapping(value = "/save")
    public User save(@EntityParam User entity) {
        User result = getService().save(entity);
        return result;
    }


    @JSON()
    @RequestMapping(value = "/query")
    public Page<User> query(@MapParam LinkedHashMap<String, Object> params, @EntityParam PageableRequest pageable) {
        Page<User> page = getService().query(params, pageable);
        return page;
    }

}
